<? include("/inc/header.html") {} ?>
<style>
.row{
	margin-bottom: 10px;
}
</style>
<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>
<!-- <script src="static/laydate/laydate.js"></script> --> <!-- 改成你的路径 -->
<div class="col-lg-12" style="overflow: auto;height: 500px;">
	<div class="panel panel">
		<div class="panel-body pan">
			<div class="form-body pal">
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">题目名称<span
						class='require'>*</span> </label>
					<div class="col-md-9">
							<div class="input-icon">
								<input id="name" type="text" class="form-control" />
							</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">题目类型
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<select class="form-control" id="type" onchange="selectType()">
									<option value="">全部</option>
									<option value="0">单选题</option>
									<option value="1">判断题</option>
									<option value="2">问答题</option>
								</select>	
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">所属题库
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<select class="form-control" id="questionDatabaseId">
								</select>
						</div>
					</div>
				</div>
				<div class="row" id="_xuanxiang" style="display: none;">
					<label for="inputUsername" class="col-md-3 control-label">选项
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div id="xuanxiang">
							<!-- <div>
								<span>A&nbsp;&nbsp;</span><input type="text" value="" class="form-control" style="display: initial;width: 60%;margin-top: 5px;">
								<button type="button" class="btn btn-red btn-square" onclick="delXuanxiang(this)"><i class="glyphicon glyphicon-trash"></i></button>
							</div> -->
						</div>
							<button type="button" class="btn btn-blue btn-square" onclick="addXuanxiang();" style="float: right;"><i class="fa fa-plus"></i></button>
					</div>
				</div>
				<div class="row" id="_xuanze" style="display:none;">
					<label for="inputUsername" class="col-md-3 control-label">题目答案
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon" id="xuanze">
							<!-- <span>
								<input type="radio" value="A" name="_xuanze">&nbsp;A&nbsp;&nbsp;
							</span>
							<span>
								<input type="radio" value="A" name="_xuanze">&nbsp;B&nbsp;&nbsp;
								</span>
							<span>
								<input type="radio" value="A" name="_xuanze">&nbsp;C&nbsp;&nbsp;
							</span> -->
						</div>
					</div>
				</div>
				<div class="row" id="_wenda" style="display: none;">
					<label for="inputUsername" class="col-md-3 control-label">题目答案
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<textarea style="width: 100%;" rows="5" id="wenda"></textarea>
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">题目解析</label>
					<div class="col-md-9">
						<!-- <div class="input-group input-group-sm mbs">
								<input id="analysis" type="text" placeholder="请点击选择" class="form-control" disabled="true">
								 <span class="input-group-btn">
								 	<button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="upFiles()">选择文件</button>
								</span>
						</div> -->
						<div class="input-icon">
							<textarea style="width: 100%;" rows="5" id="analysis"></textarea>
						</div>
					</div>
				</div>
				
			</div>
		</div>
	</div>
	<input id="id" type="hidden" value="${id}">
	<textarea id="uploadImage" name="uploadImage" style="display: none;"></textarea>
</div>
<script>
var _editor;
	$(function() {
		_editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			/* for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#coverImg").val(urlPath);
						$("#single").html("<a href="+urlPath+" download='w3logo'><img src='"+urlPath+"' width='30' height='30' /></a>");
	  	 			} */
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].url;
	  	 				$("#analysis").val(urlPath);
	  	 			}
		   	 });
	   });
	   init();
	});
	
	function init(){
		$.ajax({
			type : "post",
			url : "./questionDatabaseListPass.do",
			/* data:{
				"status":"2"
			}, */
			dataType : "json",
			success : function(data) {
				var html='<option value="">---请选择---</option>';
				for(var i in data){
					html+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
				}
				$("#questionDatabaseId").html(html);
				tiMuFind();
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
function tiMuFind(){
	if($("#id").val() != null 
		&& $("#id").val() != ''
		&& $("#id").val() != 'null'
		&& $("#id").val() != 'undefined'
		&&$("#id").val() != undefined){
		$.ajax({
			type : "post",
			url : "./questionFind.do",
			data : {
				"id" : $("#id").val()
			},
			dataType : "json",
			success : function(data) {
				$("#name").val(data[0].name);
				$("#questionDatabaseId").val(data[0].questionDatabaseId);
				$("#type").val(data[0].type);
				$("#analysis").val(data[0].analysis);
				var options = eval('(' + data[0].options + ')');
				if(data[0].type=='0'){//单选题
					$("#_xuanxiang").show();
					$("#_xuanze").show();
					$("#_wenda").hide();
					var xiangxuang='';
					var xuangze='';
					for(var i in options){
						xiangxuang+='<div><span>'+i+'&nbsp;&nbsp;</span><input type="text" value="'+options[i]+'" class="form-control" style="display: initial;width: 60%;margin-top: 5px;">';
						xiangxuang+='<button type="button" class="btn btn-red btn-square" onclick="delXuanxiang(this)"><i class="glyphicon glyphicon-trash"></i></button></div>';
						if(i==data[0].answer0){
							xuangze+='<span><input  checked="checked" type="radio" value="'+i+'" name="_xuanze">&nbsp;'+i+'&nbsp;&nbsp;</span>';
						}else{
							xuangze+='<span><input type="radio" value="'+i+'" name="_xuanze">&nbsp;'+i+'&nbsp;&nbsp;</span>';
						}
					}
					$("#xuanxiang").html(xiangxuang);
					$("#xuanze").html(xuangze);
				}else if(data[0].type=='1'){
					$("#_xuanxiang").show();
					$("#_xuanze").show();
					$("#_wenda").hide();
					var xiangxuang='';
					var xuangze='';
					for(var i in options){
						xiangxuang+='<div><span>'+i+'&nbsp;&nbsp;</span><input type="text" value="'+options[i]+'" class="form-control" style="display: initial;width: 60%;margin-top: 5px;">';
						xiangxuang+='<button type="button" class="btn btn-red btn-square" onclick="delXuanxiang(this)"><i class="glyphicon glyphicon-trash"></i></button></div>';
						if(i==data[0].answer1){
							xuangze+='<span><input  checked="checked" type="radio" value="'+i+'" name="_xuanze">&nbsp;'+i+'&nbsp;&nbsp;</span>';
						}else{
							xuangze+='<span><input type="radio" value="'+i+'" name="_xuanze">&nbsp;'+i+'&nbsp;&nbsp;</span>';
						}
					}
					$("#xuanxiang").html(xiangxuang);
					$("#xuanze").html(xuangze);
					
				}else if(data[0].type=='2'){//问答题
					$("#_xuanxiang").hide();
					$("#_xuanze").hide();
					$("#_wenda").show();
					$("#wenda").val(data[0].answer2);
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
}
</script>